package com.gepengjun.lims.util.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CommonUtil {

    public static Object covertArrayToList(String[] strings,DataType dataType){
        Object o = null;
        if (strings == null){
            return null;
        }
        if (strings.length == 0){
            return new ArrayList<>();
        }

        switch (dataType){
            case ISINT:
                o = covertToInteger(strings);
                break;
            case ISSHORT:
                o = covertToShort(strings);
                break;
            case ISLONG:
                o = covertToLong(strings);
                break;
            case ISDOUBLE:
                o = covertToDouble(strings);
                break;
            case ISBOOLEAN:
                o = covertToBoolean(strings);
                break;
            case ISSTRING:
                o = covertToString(strings);
                break;
                default:
                    o = covertToString(strings);
        }
        return o;
    }

    private static Object covertToInteger(String[] strings){
        List<String> stringList = Arrays.asList(strings);
        List<Integer> list = new ArrayList<>();
        for (String value:stringList){
            list.add(Integer.valueOf(value));
        }
        return list;
    }

    private static Object covertToShort(String[] strings){
        List<String> stringList = Arrays.asList(strings);
        List<Short> list = new ArrayList<>();
        for (String value:stringList){
            list.add(Short.valueOf(value));
        }
        return list;
    }

    private static Object covertToLong(String[] strings){
        List<String> stringList = Arrays.asList(strings);
        List<Long> list = new ArrayList<>();
        for (String value:stringList){
            list.add(Long.valueOf(value));
        }
        return list;
    }

    private static Object covertToDouble(String[] strings){
        List<String> stringList = Arrays.asList(strings);
        List<Double> list = new ArrayList<>();
        for (String value:stringList){
            list.add(Double.valueOf(value));
        }
        return list;
    }

    private static Object covertToBoolean(String[] strings){
        List<String> stringList = Arrays.asList(strings);
        List<Boolean> list = new ArrayList<>();
        for (String value:stringList){
            list.add(Boolean.valueOf(value));
        }
        return list;
    }

    private static Object covertToString(String[] strings){
        return Arrays.asList(strings);
    }
}
